﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IM.Interfaces;
using IM.Interfaces.GUI;
using IM.DataTypes;
using Common.Interfaces;

namespace IM.GUI.Widgets.ExtensionCommands
{
	class ContactListUpdateCommand : IUpdateCommand<User[]>
	{
		public void Update(User[] updatePar)
		{
			IContactList window = IM.GUI.Widgets.WidgetsProvider.Activate().ContactList;

			if (updatePar == null)
				throw new NullReferenceException("Exception in ContactListUpdateCommand occured: updatePar is null! Array of users expected!");
			if (! (updatePar is User[]))
				throw new ArgumentException("updatePar is not the expected type User[]");
			if (window == null)
			{
				Console.WriteLine(System.Threading.Thread.CurrentThread.Name);
				System.Threading.Thread.Sleep(2000);
				window = IM.GUI.Widgets.WidgetsProvider.Activate().ContactList;
				
				if (window == null)
					throw new InvalidOperationException("ContactList window is not yet initialized!");
			}
				
			window.UpdateContactList(updatePar);
		}
	}
}
